import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    //是否显示登录模块
    ifShowLoginModal: false,
    isLogined: localStorage.getItem('x-auth-token'),
    toastStatus: false,
    toastMsg: '默认内容',
    toastType:'info'
  },
  mutations: {
    showModalFn(state) {
      //显示登录模块
     state.ifShowLoginModal=true 
    },
    hideModalFn(state) {
      //关闭登录模块
      state.ifShowLoginModal=false
    },
    changeIsLogined(state) {
      //获取token
      state.isLogined = localStorage.getItem('x-auth-token')
    },
    showToast(state,payload) {
      state.toastStatus = true
      state.toastMsg = payload.msg
      state.toastType = payload.type
    },
    hideToast(state) {
      state.toastStatus = false
    }
  },
  actions: {
    //异步控制toast组件的隐藏
    changeToastAsync({ commit }, payload) {
      commit('showToast',{
        msg:payload.msg,
        type:payload.type
      })
      //两秒后隐藏
      setTimeout(() => {
       commit('hideToast')
      }, 2000);
    }
  },
  modules: {
  }
})
